package com.github.zihang.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName UserManagementController
 * @DESCRIPTION TODO
 * @Author RuanlinJing
 * @Date 2018/6/19 14:22
 * @Version 1.0
 **/
@RestController
@RefreshScope
public class UserController {
    @Value("${server.port}")
    String serverPort;

    @Value("${foo}")
    String foo;

    @GetMapping("/listUsers")
    public String ListUsers(){

        /**
         * 模拟从数据库查询
         */
        List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
        for(int i=1; i< 5; i++){
            Map<String, Object> user = new HashMap<String, Object>();
            user.put("id", i);
            user.put("name", "小明" + i);
            users.add(user);
        }
        return "服务器端口号：   " + serverPort + "   |   用户信息：   " + users.toString();
    }

    @GetMapping("/getFoo")
    public String getFooValue(){
        return foo;
    }
}
